*******************************************************
* Lyle 05 Jan 11: 						              *
*	-this program serves as a base shell for all	  *
*	 stata do files					                  *
*******************************************************


********************************
* Standard Stata Configuration *
********************************
clear all
set mem 999m
capture log close
set logtype text
cap cd "C:\Users\ejm5\Google Drive\2016_Research\Unemployment_MILEX"
cap cd "C:\Users\Jordan.Becker\Desktop\GD\2016_Research\Unemployment_MILEX"
cap cd "\\usnatonetapp01.eur.state.sbu\profiles\beckerjm\Desktop\2016_Research\Unemployment_MILEX"
log using "log\correlates_figure5.log", replace


*********************
* Prepare Variables *
*********************
use "dta\2016_02_09_uem", clear
sort ccode year
xtset ccode year


********************
* Analyze the Data *
********************
set more off
sort ccode year
xtset ccode year


*FIGURE 1: LONG-RUN EFFECTS OF CHANGES IN FOREIGN POLICY*
#delimit ;
sort ccode year;
reg d.operating l.operating l.newatlanticism d.newatlanticism  d.ln_full l.ln_full d.ln_pop l.ln_pop  d.threat l.threat  
l.sandler_strategic   d.right l.right d.dpi_checks l.dpi_checks i.year , cluster(ccode);


generate time=2016-year;
replace time=. if time>23;
generate sr=_b[d.newatlanticism];
generate lrm=-(_b[l.newatlanticism]+_b[d.newatlanticism])/(_b[l.operating]-1);

#delimit;
generate TotEff=sr+lrm;

#delimit;
gen total_effects_pos= 7.6*(TotEff*[1-(1+_b[l.operating])^(time-1)]);
replace total_effects_pos=0 if year==0;

gen
 total_effects_neg= -7.6*(TotEff*[1-(1+_b[l.operating])^(time-1)]);
replace total_effects_neg=0 if year==0;

#delimit ;
reg d.personnel l.personnel l.newatlanticism d.newatlanticism  d.ln_full l.ln_full d.ln_pop l.ln_pop  d.threat l.threat  
l.sandler_strategic   d.right l.right d.dpi_checks l.dpi_checks i.year , cluster(ccode);

generate sr2=_b[d.newatlanticism];
generate lrm2=-(_b[l.newatlanticism]+_b[d.newatlanticism])/(_b[l.personnel]-1);

#delimit;
generate TotEff2=sr2+lrm2;

#delimit;
gen total_effects_neg2= 7.6*(TotEff*[1-(1+_b[l.personnel])^(time-1)]);
replace total_effects_neg2=0 if year==0;

gen total_effects_pos2= -7.6*(TotEff*[1-(1+_b[l.personnel])^(time-1)]);
replace total_effects_pos2=0 if year==0;



#delimit;
twoway(lowess total_effects_pos time, lpattern(solid) lwidth(thick)) 
(lowess total_effects_neg time, lpattern(dash) lwidth(thick)), 
ytitle("Total Effect on Expenditures (%GDP)", margin(medium)) xtitle("Years Since Orientation Change", margin(medium))  
xlab(0(2)23) legend (size(vsmall) rows(2) position(11) ring(0) label(1 "Convergence toward Atlanticism") label(2 "Divergence from Atlanticism")) 
title("Operations");

graph save output\pred_operations.gph, replace;

#delimit;
twoway(lowess total_effects_pos2 time, lpattern(solid) lwidth(thick)) 
(lowess total_effects_neg2 time, lpattern(dash) lwidth(thick)), 
ytitle("Total Effect on Expenditures (%GDP)", margin(medium)) xtitle("Years Since Orientation Change", margin(medium))  
xlab(0(2)23) legend (size(vsmall) rows(2) position(11) ring(0) label(1 "Convergence toward Atlanticism") label(2 "Divergence from Atlanticism")) 
title("Personnel") legend(off);

graph save output\pred_personnel.gph, replace;

graph combine output\pred_operations.gph output\pred_personnel.gph, xcommon ycommon;
graph save output\Figure5.gph, replace;
